home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-06-01 | 2.4 KB | 66 lines | [TEXT/GEOL] |
- Item forwarded by LOOMIS to GUITTET1
-
- Item 4031476 30-May-90 06:13PDT
-
- From: SHEBANOW1 Shebanow, Andrew
-
- To: MACAPP.TECH$ MacApp Technical
-
- Sub: RE>RE[4] Object Style
-
- Attn: MacApp Mailing List
- SentBy: Andy Shebanow
- Reply to: RE>RE[4] Object Style
- Just to add more fuel to the Object Oriented Design fire, I would argue that
- Gets & Sets are highly suspect in a "good" object oriented design. Although I
- agree with Curtis (and with Neil Goldstein, who has spent a lot of time
- arguing with me about such things) that data members should be kept private, I
- believe that one of the keys to good object oriented design is the idea that
- an object is a protocol, and not a data structure. Providing Gets & Sets often
- runs contrary to this notion, since these functions imply an underlying data
- structure.
-
- Here is a simple (perhaps overly so) example: Lets say that we have a TView
- class, similar to the one in MacApp. One of the things about views that we
- tell people is that they have a bounding box, which we'll store internally as
- a Rect. Using the data driven approach, we define our data, and provide Gets
- and Sets to access the data cleanly:
-
- TYPE
- TView = OBJECT(TEvtHandler)
- fRect : Rect; { bounding box of view }
-
- PROCEDURE GetRect(VAR r: Rect);
- PROCEDURE SetRect(r: Rect);
- END;
-
- What's wrong with this? Not all that much, except that the design is being
- driven by its data, and not by its behavior. If you turn the problem around
- and specify the behavior of TView first, things come out looking a little
- different:
-
- TYPE
- TView = OBJECT(TEvtHandler)
- PROCEDURE GetBoundingBox(VAR r: Rect);
- PROCEDURE SetBoundingBox(r: Rect);
-
- fRect : Rect; { bounding box of view }
- END;
-
- Not very different, is it? One could argue that the only difference is in the
- naming of the functions, which could very well have been the same if better
- variable names had been chosen. The key, though, is that you've taken a step
- away from the data, and specified the behavior first. The immediate advantage
- is that it doesn't matter as much what the data structure used to store the
- bounding box is - it is the behavior of looking at or changing the bounding
- box that is important. When applied on a larger scale to an entire program,
- the difference is a lot more pronounced.
-
- Have fun,
-
- Andy Shebanow
- DTS Emeritus
- Apple Computer, Inc.
-
-
-